<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="small" @click="handleExport"
          v-hasPermi="['channel:countUvInfo:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-search" size="small" @click="handle"
          v-hasPermi="['channel:countUvInfo:count']">统计图</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="countUvInfoList">
      <el-table-column label="渠道编号" align="center" prop="channelCode" />
      <el-table-column label="渠道名称" align="center" prop="channelName" />
      <el-table-column label="应用编号" align="center" prop="appCode" />
      <el-table-column label="应用名称" align="center" prop="appName" />
      <el-table-column label="IP" align="center" prop="reqIp" />
      <el-table-column label="浏览器名称" align="center" prop="browserName" />
      <el-table-column label="平台名称" align="center" prop="platformName" />
      <el-table-column label="创建时间" align="center" width="150">
        <template slot-scope="scope">
          {{ formatTimestamp(scope.row.createTime) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <Count ref="CountRef" />
  </div>
</template>

<script>
import { listCountUvInfo } from "@/api/channel/countUvInfo";
import Count from '@/views/channel/countUvInfo/echars/count.vue'
export default {
  components: {
    Count
  },
  name: "CountUvInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 渠道统计uv信息表格数据
      countUvInfoList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        channelName: null,
        appCode: null,
        appName: null,
        randomId: null,
        reqIp: null,
        browserName: null,
        platformName: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.queryParams = {
      ...this.queryParams,
      ...this.$route.query
    }
    this.getList();
  },
  watch:{
    $route(){
      this.getList()
    }
  },
  methods: {
    /**更改创建时间格式 */
    formatTimestamp(timestamp) {
      if (!timestamp) {
        return '';
      }
      const date = new Date(timestamp);
      const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
      return formattedDate;
    },
    /** 查询渠道统计uv信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.channelCode = this.$route.query.channelCode;
      this.queryParams.dateInfo = this.$route.query.dateInfo;
      listCountUvInfo(this.queryParams).then(response => {
        this.countUvInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dateInfo: null,
        channelCode: null,
        reqIp: null,
        createTime: null
      };
      this.resetForm("form");
    },

    handle() {
      this.$refs.CountRef.show(this.queryParams)
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('channel/countUvInfo/export', {
        ...this.queryParams
      }, `countUvInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


<style>
.dialog-footer {
    text-align: right;
}
</style>
